﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using System.IO;


namespace CPF_experement
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 0
            //bool[][] grid = new bool[3][];
            //for (int i = 0; i < 3; i++)
            //{
            //    grid[i] = new bool[3];
            //}

            ////grid[1][1] = true;
            ////grid[1][0] = true;
            ////for (int i = 0; i < 4; i++)
            ////{
            ////    grid[i][3] = true;
            ////}
            ////for (int i = 0; i < 4; i++)
            ////{
            ////    if (i != 2)
            ////    {
            ////        grid[i][1] = true;
            ////        grid[i][2] = true;
            ////    }
            ////}

            //Agent a = new Agent(0, 0, 0);
            //Agent aa = new Agent(0, 1, 1);
            //Agent aaa = new Agent(1, 0, 2);
            ////Agent aaaa = new Agent(1, 2, 3);
            ////Agent aaaaa = new Agent(0, 2, 4);
            ////Agent aaaaaa = new Agent(2, 2, 5);
            ////Agent aaaaaaa = new Agent(0, 1, 6);
            ////Agent aaaaaaaa = new Agent(2, 0, 7);
            //Agent[] d = new Agent[3];

            //d[0] = a;
            //d[1] = aa;
            //d[2] = aaa;
            ////d[3] = aaaa;
            ////d[4] = aaaaa;
            ////d[5] = aaaaaa;
            ////d[6] = aaaaaaa;
            ////d[7] = aaaaaaaa;
            //True_Path_Huristic.init(3, 3, d, false, grid);

            //AgentState b = new AgentState(2, 1, a);
            //AgentState bb = new AgentState(0, 2, aa);
            //AgentState bbb = new AgentState(1, 0, aaa);
            ////AgentState bbbb = new AgentState(0, 1, aaaa);
            ////AgentState bbbbb = new AgentState(1, 1, aaaaa);
            ////AgentState bbbbbb = new AgentState(0, 0, aaaaaa);
            ////AgentState bbbbbbb = new AgentState(1, 2, aaaaaaa);
            ////AgentState bbbbbbbb = new AgentState(1, 0, aaaaaaaa);
            //AgentState[] c = new AgentState[3];
            //c[0] = b;
            //c[1] = bb;
            //c[2] = bbb;
            ////c[3] = bbbb;
            ////c[4] = bbbbb;
            ////c[5] = bbbbbb;
            ////c[6] = bbbbbbb;
            ////c[7] = bbbbbbbb;

            //Run.solveGivenProblem(grid, c);

            //Console.ReadLine();
            #endregion
            #region 1

            //bool[][] grid = new bool[256][];
            //for (int i = 0; i < 256; i++)
            //{
            //    grid[i] = new bool[256];
            //}

            //try
            //{
            //    // Create an instance of StreamReader to read from a file.
            //    // The using statement also closes the StreamReader.
            //    using (StreamReader sr = new StreamReader("0.map"))
            //    {
            //        string line;
            //        int y = 0;
            //        sr.ReadLine();
            //        sr.ReadLine();
            //        sr.ReadLine();
            //        sr.ReadLine();
            //        // Read and display lines from the file until the end of 
            //        // the file is reached.
            //        while ((line = sr.ReadLine()) != null)
            //        {
            //            for (int x = 0; x < line.Length; x++)
            //            {
            //                if (line[x].Equals('@'))
            //                {
            //                    grid[x][y]=true;
            //                }
            //            }

            //            y++;
            //        }
            //    }
            //}
            //catch (Exception e)
            //{
            //    // Let the user know what went wrong.
            //    Console.WriteLine("The file could not be read:");
            //    Console.WriteLine(e.Message);
            //}


            //object misValue = System.Reflection.Missing.Value;

            //Excel.Application excelApp = new Excel.Application();
            //string myPath = @"C:\1\ResultsWithNewAlgo.xlsx";
            //excelApp.Workbooks.Open(myPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            //Run.row = 2;

            ////excelApp.Cells[1, 1] = "Instance";
            ////excelApp.Cells[1, 2] = "Algoritem";
            ////excelApp.Cells[1, 3] = "Grid";
            ////excelApp.Cells[1, 4] = "Obsticals#";
            ////excelApp.Cells[1, 5] = "Agents#";
            ////excelApp.Cells[1, 6] = "Time";
            ////excelApp.Cells[1, 7] = "Total Cost";
            ////excelApp.Cells[1, 8] = "Generated";
            ////excelApp.Cells[1, 9] = "Expanded";
            ////excelApp.Cells[1, 10] = "Success";
            ////excelApp.Cells[1, 11] = "%Optimal";
            ////excelApp.Cells[1, 12] = "Trevor min group size";
            ////excelApp.Cells[1, 13] = "Trevor max group size";

            //excelApp.Cells[1, 1] = "Instance";
            //excelApp.Cells[1, 2] = "Agents#";
            //excelApp.Cells[1, 3] = "superTree genereted";
            //excelApp.Cells[1, 4] = "total brute force";
            //excelApp.Cells[1, 5] = "create MDD tome";
            //excelApp.Cells[1, 6] = "syncronize time";
            //excelApp.Cells[1, 7] = "brute force time";
            //excelApp.Cells[1, 8] = "total time";

            //    for (int a = 2; a <= 20; a++)
            //    {
            //        for (int i = 0; i < 5; i++)
            //        {
            //            Run.solveGivenGrid(grid, a, i, excelApp);
            //        }
            //    }
           
 
#endregion

            #region 2
            //object misValue = System.Reflection.Missing.Value;

            //Excel.Application excelApp = new Excel.Application();
            //string myPath = @"C:\1\ResultsWithNewAlgo.xlsx";
            //excelApp.Workbooks.Open(myPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            //Run.row = 2;
            //int ob;

            //excelApp.Cells[1, 1] = "Instance";
            //excelApp.Cells[1, 2] = "Algoritem";
            //excelApp.Cells[1, 3] = "Grid";
            //excelApp.Cells[1, 4] = "Obsticals#";
            //excelApp.Cells[1, 5] = "Agents#";
            //excelApp.Cells[1, 6] = "Time";
            //excelApp.Cells[1, 7] = "Total Cost";
            //excelApp.Cells[1, 8] = "Generated";
            //excelApp.Cells[1, 9] = "Expanded";
            //excelApp.Cells[1, 10] = "Success";
            //excelApp.Cells[1, 11] = "%Optimal";
            //excelApp.Cells[1, 12] = "Trevor min group size";
            //excelApp.Cells[1, 13] = "Trevor max group size";

            //for (int o = 0; o < 4; o++)
            //{
            //    for (int a = 1; a <= 9; a++)
            //    {
            //        for (int i = 0; i < 2; i++)
            //        {
            //            Run.generateAndSolve(3, a, o, i, excelApp);
            //        }
            //    }
            //}

            //for (double o = 0; o < 11; o = o + 2.5)
            //{
            //    ob = (int)Math.Round(o, 0);
            //    Run.A_Star_OutOfTime = 0;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 1; a <= 10; a++)
            //    {
            //        for (int i = 0; i < 2; i++)
            //        {
            //            Run.generateAndSolve(5, a, ob, i, excelApp);
            //        }
            //    }
            //}

            //for (int o = 0; o < 41; o = o + 10)
            //{
            //    Run.A_Star_OutOfTime = 11;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 0; a <= 97; a++)
            //    {
            //        for (int i = 0; i < 2; i++)
            //        {
            //            Run.generateAndSolve(10, a, o, i, excelApp);
            //        }
            //    }
            //}

            //for (int o = 0; o <= 4000; o = o + 1000)
            //{
            //    Run.A_Star_OutOfTime = 0;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 1; a <= 50; a++)
            //    {
            //        for (int i = 0; i < 2; i++)
            //        {
            //            Run.generateAndSolve(100, a, o, i, excelApp);
            //        }
            //    }
            //}


            //excelApp.Visible = true;
            #endregion

            #region 3
            //object misValue = System.Reflection.Missing.Value;

            //Excel.Application excelApp = new Excel.Application();
            //string myPath = Directory.GetCurrentDirectory()+@"\Results3X3&5X5.xlsx";
            ////string myPath = Directory.GetCurrentDirectory() + @"\Results10X10.xlsx";
            ////string myPath = Directory.GetCurrentDirectory() + @"\Results100X100.xlsx";
            ////excelApp.Workbooks.Close();
            
            
            //excelApp.Workbooks.Open(myPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            //Run.row = 2;
            //int ob;

            //excelApp.Cells[1, 1] = "Grid";
            //excelApp.Cells[1, 2] = "Obsticals#";
            //excelApp.Cells[1, 3] = "Agents#";
            //excelApp.Cells[1, 4] = "Instance";
            //excelApp.Cells[1, 5] = "Trevor time";
            //excelApp.Cells[1, 6] = "superTree epanded";
            //excelApp.Cells[1, 7] = "total brute force";
            //excelApp.Cells[1, 8] = "create MDD time";
            //excelApp.Cells[1, 9] = "syncronize time";
            //excelApp.Cells[1, 10] = "brute force time";
            //excelApp.Cells[1, 11] = "total time";

            //Run.row = 2;
            //for (int o = 0; o < 4; o++)
            //{
            //    for (int a = 2; a <= 8 - o; a++)
            //    {
            //        for (int i = 0; i < 30; i++)
            //        {
            //            Run.generateAndSolveTimeTest(3, a, o, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}

            //for (double o = 0; o < 11; o = o + 2.5)
            //{
            //    ob = (int)Math.Round(o, 0);
            //    Run.A_Star_OutOfTime = 0;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 2; a <= 15; a++)
            //    {
            //        for (int i = 0; i < 30; i++)
            //        {
            //            Run.generateAndSolveTimeTest(5, a, ob, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}
            ////bool first = true;
            //for (int o = 30; o < 41; o = o + 10)
            //{
            //    Run.A_Star_OutOfTime = 11;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 2; a <= 20; a++)
            //    {
            //        //if (first)
            //        //{
            //        //    a = 13;
            //        //}
            //        for (int i = 0; i < 30; i++)
            //        {
            //            //if (first)
            //            //{
            //            //    i = 1;
            //            //    first = false;
            //            //}
            //            Run.generateAndSolveTimeTest(10, a, o, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}

            //for (int o = 0; o <= 4000; o = o + 1000)
            //{
            //    for (int a = 2; a <= 50; a++)
            //    {
            //        //if (first)
            //        //{
            //        //    a = 19;
            //        //}
            //        for (int i = 0; i < 30; i++)
            //        {
            //            //if (first)
            //            //{
            //            //    i = 1;
            //            //    first = false;
            //            //}
            //            Run.generateAndSolveTimeTest(100, a, o, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();

            //        }
            //    }
            //}


            //excelApp.Visible = true;
            #endregion
            #region 4
            object misValue = System.Reflection.Missing.Value;

            Excel.Application excelApp = new Excel.Application();
            //string myPath = Directory.GetCurrentDirectory() + @"\Results3X3&5X5.xlsx";
            string myPath = Directory.GetCurrentDirectory() + @"\copath100X100X400.xlsx";
            //string myPath = Directory.GetCurrentDirectory() + @"\Results100X100.xlsx";
            //excelApp.Workbooks.Close();


            excelApp.Workbooks.Open(myPath, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
            Run.row = 2;
            int ob;

            excelApp.Cells[1, 1] = "Grid";
            excelApp.Cells[1, 2] = "Obsticals#";
            excelApp.Cells[1, 3] = "Agents#";
            excelApp.Cells[1, 4] = "Instance";
            excelApp.Cells[1, 5] = "Trevor time";
            excelApp.Cells[1, 6] = "New alg time";
            excelApp.Cells[1, 7] = "Trevor success";
            excelApp.Cells[1, 8] = "New success";
            excelApp.Cells[1, 9] = "T MinGroup";
            excelApp.Cells[1, 10] = "T MaxGroup";
            excelApp.Cells[1, 11] = "N MinGroup";
            excelApp.Cells[1, 12] = "N MaxGroup";

            Run.row = 812;
            //for (int o = 0; o < 4; o++)
            //{
            //    for (int a = 2; a <= 8 - o; a++)
            //    {
            //        for (int i = 0; i < 30; i++)
            //        {
            //            Run.generateAndSolveWithIndependate(3, a, o, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}

            //for (double o = 0; o < 11; o = o + 2.5)
            //{
            //    ob = (int)Math.Round(o, 0);
            //    Run.A_Star_OutOfTime = 0;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 2; a <= 15; a++)
            //    {
            //        for (int i = 0; i < 30; i++)
            //        {
            //            Run.generateAndSolveWithIndependate(5, a, ob, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}
            bool first = true;
            //for (int o = 10; o < 41; o = o + 10)
            //{
            //    Run.A_Star_OutOfTime = 11;
            //    Run.trevor_OutOfTime = 0;
            //    for (int a = 2; a <= 20; a++)
            //    {
            //        if (first)
            //        {
            //            a = 14;
            //        }
            //        for (int i = 0; i < 30; i++)
            //        {
            //            if (first)
            //            {
            //                i = 2;
            //                first = false;
            //            }
            //            Run.generateAndSolveWithIndependate(10, a, o, i, excelApp);
            //            excelApp.ActiveWorkbook.Save();
            //        }
            //    }
            //}

            for (int o = 4000; o <= 4000; o = o + 1000)
            {
                for (int a = 2; a <= 100; a+=5)
                {
                    if (first)
                    {
                        a = 29;
                    }
                    for (int i = 0; i < 30; i++)
                    {
                        if (first)
                        {
                            i = 0;
                            first = false;
                        }
                        if (!Run.generateAndSolveWithIndependate(100, a, o, i, excelApp)) i--;
                        excelApp.ActiveWorkbook.Save();

                    }
                }
            }


            excelApp.Visible = true;
            #endregion
            Console.ReadLine();
        }    
    }
}
